<template>
    <div>
      <h2 class="demo">姓名：{{ name }}</h2>
      <h2>age{{ age }}</h2>
      
    </div>
</template>
  
  
  
<script>
  //引入第三方实现发布订阅的库
  import pubsub from 'pubsub-js'
  export default {
      name:'You',
      data(){
          return {
              name:'李四',
              age:18
          }
      },
      methods:{
          hi(mesName,name){
            console.log('@',mesName,'hello ! i am ',name)
          }
      },
      mounted(){
        //订阅消息
        this.pubId = pubsub.subscribe('hi',this.hi)
      },
      beforeDestroy() {
        pubsub.unsubscribe(this.pubId)
      }
  }
</script>

<style scoped>
  .demo {
    color: blue;
  }
</style>
  